package com.leetcode.LeetCode精选TOP面试题;

/**
 * @author 覃国强
 * @date 2022-07-05 17:01
 */
public class 题库_0169_多数元素 {

  static
  class Solution {
    public int majorityElement(int[] nums) {
      if (nums == null || nums.length == 0) {
        return -1;
      }
      int count = 0;
      int answer = 0;
      for (int num : nums) {
        if (count == 0) {
          answer = num;
        }
        count += answer == num ? 1 : -1;
      }
      return answer;
    }
  }

}
